﻿using Microsoft.Practices.Unity;
using RG.Common;

namespace RG.Common.WPF.Dialogs
{
    [SupportDataBinding]
    public class DialogWindowVM : IChildView, IWorkplaceObject
    {
        [Dependency]
        public IUnityContainer Cfg { get; set; }

        public object Child { get; private set; }

        public object ChildView { get; private set; }

        public void SetChild<TPresenter>(TPresenter child)
        {
            Child = child;

            var view = Cfg.Resolve<IView<TPresenter>>();
            view.Presenter = child;
            ChildView = view;
        }

        public bool CanClose
        {
            get
            {
                var wo = Child as IWorkplaceObject;
                return (wo == null) || wo.CanClose;
            }
        }
    }
}
